import { http } from "@/utils/http";
import { baseUrlApi } from "@/utils/http/utils";
import { logInfoType, ResultCommon, ResultCommonList, ResultPagination } from "@/utils/commonType";

/** 获取日志清单 */
export const getLogList = async (data?: object) => {
  const result = await http.request<ResultPagination<logInfoType>>(
    "get",
    baseUrlApi("/logs/search"),
    {
      params: data
    }
  );
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};

/** 获取日志清单 */
export const getLogListForPub = async (tenantId: string, data?: object) => {
  const result = await http.request<ResultPagination<logInfoType>>(
    "get",
    baseUrlApi("/logs/searchForPub/" + tenantId),
    {
      params: data
    }
  );
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};

/** 获取日志清单 */
export const getLogListForCall = async (tenantId: string, data?: object) => {
  const result = await http.request<ResultPagination<logInfoType>>(
    "get",
    baseUrlApi("/logs/searchForCall/" + tenantId),
    {
      params: data
    }
  );
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
};

export const updateLogSettings = async (serviceId: string, data: any) => {
  const result = await http.request<ResultPagination<logInfoType>>(
    "put",
    baseUrlApi("/logs/settings/update/" + serviceId),
    {
      data: data
    }
  );
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
}

export const getLogSettings=async(serviceId:string)=>{
  const result = await http.request<ResultCommon<any>>(
    "get",
    baseUrlApi("/logs/settings/" + serviceId)
  );
  if (result.code != 200) {
    throw new Error(result.message);
  }
  return result;
}